/*
(c) 2010 - Open Source Business Foundation e. V. (www.osbf.de)
This software is provided under Microsoft Reciprocal License (Ms-RL)
(http://www.microsoft.com/opensource/licenses.mspx#Ms-RL)
All other rights reserved
*/

function walkChildNodes(doc, objRef, n) {
  var obj;
  if (objRef) {
    if (typeof objRef == "string") {
      obj = doc.getElementById(objRef);
    } else {
      obj = objRef;
    }
  } else {
    obj = (doc.body.parentElement) ? doc.body.parentElment : doc.body.parentNode;
  }
  var output = "";
  var indent = "";
  var i, group, txt;
  if (n) {
    for (i = 0; i < n; i++) {
      indent += "+--";
    }
  } else {
    n = 0;
    output += "Child Nodes of <" + obj.tagName.toLowerCase();
    output += ">\n========================================\n";
  }
  group = obj.childNodes;
  for (i = 0; i < group.length; i++) {
    output += indent;
    switch (group[i].nodeType) {
      case 1:
        output += "<" + group[i].tagName.toLowerCase();
        output += (group[i].id) ? " ID=" + group[i].id : "";
        output += (group[i].name) ? " NAME=" + group[i].name : "";
        output += ">\n";
        break;
      case 3:
        txt = group[i].nodeValue.substr(0, 15);
        output += "[Text:\"" + txt.replace(/[\r\n]/g, "<cr>");
        if (group[i].nodeValue.length > 15) {
          output += "...";
        }
        output += "\"]\n";
        break;
      case 8:
        output += "[!COMMENT!]\n";
        break;
      default:
        output += "[Node Type = " + group[i].nodeType + "]\n";
    }
    if (group[i].childNodes.length > 0) {
      output += walkChildNodes(doc, group[i], n+1);
    }
  }
  return output;
}

function listProperties(obj, objName) {
  var result = "";
  for (var i in obj) {
    result += objName + "." + i + "=" + obj[i] + "\n";
  }
  return result;
}

